package com.meusdrinks.view;

import javax.faces.bean.ManagedBean;
import javax.inject.Inject;

import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.annotation.ViewScoped;
import br.gov.frameworkdemoiselle.template.AbstractEditPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;

import com.meusdrinks.business.DrinkBC;
import com.meusdrinks.business.IngredienteBC;
import com.meusdrinks.business.UsuarioBC;
import com.meusdrinks.domain.Drink;

@ManagedBean
@ViewScoped
@PreviousView("./avaliar.jsf")
public class AvaliarEditMB extends AbstractEditPageBean<Drink, Long>{
	
	private static final long serialVersionUID = 1L;

	@Inject
	private DrinkBC drinkBC;
	
	@Inject
	private IngredienteBC ingredienteBC;
	
	@Inject
	private UsuarioBC usuarioBC;
	
	private Integer nota;
	
	public String avaliar(){
		handleLoad();
		getBean().setSomaNotas(getBean().getSomaNotas() + nota);
		drinkBC.update(getBean());
		return "ranking.jsf";
	}
	
	
	@Override
	@Transactional
	public String delete() {
		this.drinkBC.delete(getId());
		return getPreviousView();
	}
	
	@Override
	@Transactional
	public String insert() {
		this.drinkBC.insert(getBean());
		return getPreviousView();
	}
	
	@Override
	@Transactional
	public String update() {
		getBean().setSomaNotas(getBean().getSomaNotas() + nota);
		this.drinkBC.update(getBean());
		return getPreviousView();
	}
	
	@Override
	protected void handleLoad() {
		setBean(this.drinkBC.load(getId()));
	}

	public Integer getNota() {
		return nota;
	}


	public void setNota(Integer nota) {
		this.nota = nota;
	}

}
